<template>
  <el-form :inline="true" :model="ruleForm" :rules="rules" ref="ruleForm" label-position="right"  label-width="110px" class="small-space">
    <el-form-item label="收取金額(元)" prop="price">
      <el-input-number v-model="ruleForm.price"></el-input-number>
    </el-form-item>
    <el-form-item label="停卡時間" prop="date">
      <el-date-picker
        v-model="ruleForm.date"
        type="daterange"
        align="right"
        placeholder="选择日期范围"
        :picker-options="pickerOptions2">
      </el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import { rules } from '@/utils/rules'

  export default{
    props: {
      stopCardId: {
        default: null
      }
    },
    data () {
      return {
        pickerOptions2: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        ruleForm: {
          price: '',
          date: ''
        },
        rules: {
          price: {required:true, message: '请输入收取金额'},
          date: {required:true, message: '请选择停卡日期'}
        },
      }
    },
    watch: {
      stopCardId () {
        console.log(this.stopCardId)
      }
    },
    methods: {
      submitForm(formName){
        console.log('1', this.stopCardId)
        this.$refs[formName].validate((valid) => {
          if (valid) {this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 5000 });
            this.reloadList()
            this.resetForm('ruleForm')
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
    created () {
      console.log('stopCard created')

    }
  }
</script>

<style scoped>
  .el-col-12 .el-form-item{
    margin-bottom: 17px;
  }
  .p-button{
    width: 250px; text-align: center;padding-top: 20px
  }
</style>
